package cn.tedu.xzs.admin.questionmanagement.service.impl;


import cn.tedu.xzs.admin.questionmanagement.dao.persist.repository.AnswerRepository;
import cn.tedu.xzs.admin.questionmanagement.dao.persist.repository.QuestionRepository;
import cn.tedu.xzs.admin.questionmanagement.pojo.entity.Answer;
import cn.tedu.xzs.admin.questionmanagement.pojo.param.AnswerAddNewParam;
import cn.tedu.xzs.admin.questionmanagement.service.AnswerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AnswerServiceImpl implements AnswerService {

    @Autowired
    private AnswerRepository answerRepository;
    @Autowired
    private QuestionRepository questionRepository;
    @Override
    public int addNew(AnswerAddNewParam answerAddNewParam) {
        Answer answer = new Answer();
        BeanUtils.copyProperties(answerAddNewParam,answer);
        answer.setQuestionId(questionRepository.getLatestQuestionId());
        return answerRepository.addNew(answer);
    }
}
